﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VMultiAPI;

namespace ZSens
{
    class Layout
    {
        protected List<Widget> widgets;
        public Layout()
        {
            widgets = new List<Widget>
            {
                new OrientationX(),
                new OrientationY(),
                new Button((float) 0.25, (float) 0.4, (float) 0.75, (float) 0.5),
                new Button((float) 0.25, (float) 0.6, (float) 0.75, (float) 0.7),
            };
        }
        public string Serialize()
        {
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < widgets.Count; i++)
            {
                sb.Append((int)i);
                widgets[i].Serialize(sb);
            }
            return sb.ToString();
        }
        public void DoVMultiUpdate()
        {
            foreach (var widget in widgets)
                foreach (var action in widget.BindedAction)
                    action.DoVMultiUpdate();
        }
    }
    //TODO : Remove these specialized classes
    class BallanceLayout
        : Layout
    {
        public BallanceLayout()
        {
            var ox = new OrientationX();
            ox.BindedAction = new List<Action>
            {
                new PressKeyboardKeyAction(
                    new FloatToBool(ox,0.5f,new Range { Start = 0.5f, End = 0f } ),
                    new List<Keyboard.KeyCode> { Keyboard.KeyCode.KeyLeftArrow }
                    ),
                new PressKeyboardKeyAction (
                    new FloatToBool(ox,0.5f,new Range { Start = 0.5f ,End = 1f} ),
                    new List<Keyboard.KeyCode> { Keyboard.KeyCode.KeyRightArrow }
                    )
            };
            var oy = new OrientationY();
            oy.BindedAction = new List<Action>
            {
                new PressKeyboardKeyAction(
                    new FloatToBool(oy,0.5f,new Range { Start = 0.5f , End = 0f } ),
                    new List<Keyboard.KeyCode> { Keyboard.KeyCode.KeyUpArrow }
                    ),
                new PressKeyboardKeyAction (
                    new FloatToBool(oy,0.5f,new Range { Start = 0.5f ,End = 1f} ),
                    new List<Keyboard.KeyCode> { Keyboard.KeyCode.KeyDownArrow }
                    )
            };
            var but1 = new Button();
            but1.BindedAction = new List<Action>
            {
                new PressKeyboardKeyAction(but1,new List<Keyboard.KeyCode>{ Keyboard.KeyCode.KeyLeftShift,Keyboard.KeyCode.KeyLeftArrow } )
            };
            var but2 = new Button();
            but2.BindedAction = new List<Action>
            {
                new PressKeyboardKeyAction(but2,new List<Keyboard.KeyCode>{ Keyboard.KeyCode.KeyLeftShift,Keyboard.KeyCode.KeyRightArrow } )
            };
            widgets = new List<Widget>
            {
                ox,oy,
                but1,but2
            };
        }
    }

    class NeedForSpeedLayout
        : Layout
    {
        public NeedForSpeedLayout()
        {
            var ox = new OrientationX();
            ox.BindedAction = new List<Action>
            {
                new SetJoystickAxisAction(ox,JoystickAxis.X)
            };
            var oy = new OrientationY();
            oy.BindedAction = new List<Action>
            {
                new SetJoystickAxisAction(oy,JoystickAxis.Y)
            };
            var but1 = new Button();
            but1.BindedAction = new List<Action>
            {
                new PressJoystickButtonAction(but1,new List<int>{0})
            };
            var but2 = new Button();
            but2.BindedAction = new List<Action>
            {
                new PressJoystickButtonAction(but2,new List<int>{1})
            };
            widgets = new List<Widget>
            {
                ox,oy,but1,but2
            };
        }
    }
}
